Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Objects /
Chapter 1 - Introduction to QuickDraw GX / QuickDraw GX Objects


Advantages of an Object-Based Structure

QuickDraw GX is currently implemented in the C programming language, which is not in itself object-oriented. Nevertheless, using QuickDraw GX gives you some of the fundamental programming advantages available with object-based systems.

QuickDraw GX objects are private. You do not usually have direct access to the internal data in a QuickDraw GX object; you instead make function calls to manipulate the information. This information hiding means that objects behave more consistently, unwanted side effects are minimized, and QuickDraw GX itself can take care of housekeeping tasks like tracking the current number of users of an object. It also means that QuickDraw GX can locate objects in memory managed by a graphics accelerator--memory that is not necessarily accessible to your application.

By analogy with the polymorphism of some object-oriented systems, QuickDraw GX functions are organized so that a single function can apply to many types of objects. For example, a single drawing command (GXDrawShape) draws any QuickDraw GX shape, from a point to a curve to a bitmap to a line of text. Furthermore, there are many classes of calls that, while defined individually for each kind of object they apply to (in order to facilitate type-checking in Pascal and C), are completely parallel in function and in syntax. For example, the functions GXGetShapeTags, GXGetStyleTags, and GXGetInkTags take the same parameter (an object reference) and perform the same task (return a list of associated tag objects), but each for a different kind of object.

QuickDraw GX objects can be shared. To save duplication and prevent the accumulation of excessive numbers of objects in memory, QuickDraw GX allows multiple references to a single object. QuickDraw GX tracks the number of references to an object. When you are finished with an object, you dispose of it; QuickDraw GX then makes sure that the object is not being used for any other purpose before actually deleting it from memory.

Creating a QuickDraw GX object is somewhat like instantiating a class in an object-oriented system. When you first create a QuickDraw GX object it typically
has default values that you can use or change to suit your needs.

Object-manipulation functions are mostly consistent across all objects; categories
include GXNewObject (makes a new object), GXDisposeObject (deletes the object), GXCopyToObject (copies an object), GXEqualObject (tests two objects for equality),
and GXCloneObject (makes a shared reference). Object-editing functions are
similarly consistent, and include GXGetObjectProperty (to retrieve values) and GXSetObjectProperty (to assign values). By combining GXGetObject and GXSetObject calls with index values and ranges, you can insert, delete, and replace all or parts
of arrays of values within an object.

The QuickDraw GX environment provides other consistencies to make programming tasks more straightforward. Many are listed in the section "Programming Conventions and Consistencies" beginning on page 1-41.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996